﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Common;

namespace ThuongMaiDienTu.Shared
{
    public partial class Main : System.Web.UI.MasterPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session[Column.User] != null)
            {
                login_box.Visible = false;
                logout_box.Visible = true;
            }
            else
            {
                login_box.Visible = true;
                logout_box.Visible = false;
            }
            if (!IsPostBack)
            {
            }
        }

        protected void bnt_dangnhap_Click(object sender, EventArgs e)
        {
            string key = System.Configuration.ConfigurationManager.AppSettings["KeySecurity"].ToString();
            string username = txt_username.Text;
            string password = txt_pass.Text;

            var user = (from c in Db.data.Tb_Users
                            where  c.UserName == username
                            select new
                            {c}).SingleOrDefault();

            
            if(user != null)
            {
                if (algorithmPassword.Encode(password, key) == user.c.MatKhau)
                {
                    Session[Column.User] = user;
                }
                else
                {

                }
            }
        }

  
    }
}